package com.leetcode.contest;

import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2021/11/13 22:31
 */
public class LC5910检查两个字符串是否几乎相等 {

    public static boolean checkAlmostEquivalent(String word1, String word2) {
        int[] cnt1 = new int[26], cnt2 = new int[26];
        for (int i = 0; i < word1.length(); i++) cnt1[word1.charAt(i) - 'a']++;
        for (int i = 0; i < word2.length(); i++) cnt2[word2.charAt(i) - 'a']++;
        for (int i = 0; i < 26; i++) {
            if (Math.abs(cnt1[i] - cnt2[i]) > 3) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(checkAlmostEquivalent("cccddabba", "babababab"));
    }
}
